package com.devtools.project.tool.swagger.service;

import com.alibaba.fastjson.JSONObject;
import com.devtools.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.devtools.project.tool.swagger.mapper.SwaggerMapper;
import com.devtools.project.tool.swagger.domain.ToolSwagger;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Map;

/**
 * swagger接口 服务层实现
 *
 * @author devtools
 * @date 2022-11-28
 */
@Service
public class SwaggerServiceImpl extends ServiceImpl<SwaggerMapper, ToolSwagger> implements ISwaggerService {
    @Autowired
    private WordService wordService;

    @Override
    public JSONObject generateModelData(Integer swaggerId) {
        JSONObject data = new JSONObject();
        ToolSwagger swagger = getById(swaggerId);
        Map<String, Object> result ;
        if (StringUtils.isEmpty(swagger.getJsonStr())||swagger.getJsonStr().length()<10){
            result = wordService.tableList(swagger);
        }else {
            result = wordService.tableListFromString(swagger.getJsonStr());
        }
        data.put("url", swagger.getSwaggerJsonUrl());
        data.put("download", 1);
        data.put("swagger", swagger);
        data.putAll(result);
        data.put("docName", swagger.getProjectName() + "接口文档");
        return data;
    }


}
